package com.crm.dao.purchaseDAO;

import com.crm.pojo.Purchase;
import com.crm.vo.PurchaseUserInfoVO;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface PurchaseDAO extends CrudRepository<Purchase,Long>, JpaSpecificationExecutor<Purchase> {
    //模糊查询根据采购标题或采购id
    @Query(nativeQuery = true,value = "select * from PURCHASE p where p.PURCHASE_IS_DEL='否'and p.PURSTATUS='采购完成-待入库' and (p.PURID like?1 or p.PURTHEME like?1)")
    public List<Purchase> findAllpurBymh(String q);
    //分页查询所有采购单 时间排序
    @Query("from Purchase  p where p.purchaseIsDel='否'order by p.purdate desc")
    public List<Purchase> findAllByPaged(Pageable pageable);
    //模糊查询根据采购标题或经手人名称（真名）
    @Query("select new com.crm.vo.PurchaseUserInfoVO(p,u) from  Purchase  p,Userinfo u where p.purchaseIsDel='否'and (p.purtheme like?1 or u.urealName like?1) and u.uId=p.purUserId")
    public List<PurchaseUserInfoVO> findAllpurBymh2(String q);
    //模糊查询采购单根据采购标题
    @Query("from Purchase p where p.purchaseIsDel='否'and p.purstatus!='待采购'and p.purtheme like ?1 order by p.purdate desc")
    public List<Purchase> findAllpurBythemeMh(String q);
    //根据采购商id获取采购单集合
    @Query("from Purchase p where p.clientId=?1")
    public List<Purchase> findAllByClientId(Long clientId);
    //模糊查询根据采购标题或采购id
    @Query(nativeQuery = true,value = "select * from PURCHASE p where p.PURCHASE_IS_DEL='否'and p.PURSTATUS='采购完成-待入库'")
    public List<Purchase> findAllpurBymhnone();
    @Query(nativeQuery = true,value = "select * from PURCHASE p where p.PURCHASE_IS_DEL='否' and p.PURID=?1 and p.PURSTATUS!='采购完成-已入库'")
    public Purchase findOneByid(Long purid);

}
